/**
 * Created by hejiahui on 2018/6/22.
 */

// 连接数据库

var mongoose =  require('mongoose')

const options = {
    user: 'admin',
    pwd: '123456',
    host: 'localhost',
    port: '27017',
    database: 'hollywood',
    authSource: 'admin',
}

const  url = "mongodb://localhost:27017/taskMan";
//const uri = `mongodb://${options.user}:${options.pwd}@${options.host}:${options.port}/${options.database}?authSource=${options.authSource}`
//mongoose.Promise = global.Promise //需要
mongoose.connect(url,  {useNewUrlParser: true })
var db = mongoose.connection
db.on('error',console.error.bind(console,'连接错误:'));
db.once('open',function(){
    //一次打开记录
    console.log('连接成功')
});

module.exports = mongoose

/*
module.exports = {
    connect(){
        var MongoClient = require('mongodb').MongoClient;
        var url = "mongodb://localhost:27017/";

        MongoClient.connect(url, function(err, db) {
            if (err) throw err;
            var dbo = db.db("runoob");
            var mysort = { type: 1 };
            dbo.collection("site").find().sort(mysort).toArray(function(err, result) {
                if (err) throw err;
                console.log(result);
                db.close();
            });
        });
    }
}*/


